package top.sssd.auth.config;

import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.TimeZone;

import static top.sssd.auth.common.constant.CommonConstant.COMMON_DATE_FORMAT;
import static top.sssd.auth.common.constant.CommonConstant.COMMON_TIMEZONE;

@Configuration
public class JacksonConfig {
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
        return builder -> {
            // 设置全局日期格式
            builder.serializerByType(LocalDateTime.class,
                    new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(COMMON_DATE_FORMAT)));

            // 设置时区（可选，默认使用系统时区）
            builder.timeZone(TimeZone.getTimeZone(COMMON_TIMEZONE));
        };
    }
}
